<?php
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
class table_aljbd_notice extends discuz_table{
	public function __construct() {

			$this->_table = 'aljbd_notice';
			$this->_pk    = 'id';

			parent::__construct();
	}
	public function count_by_uid_bid($uid=0,$bid=0,$type=0,$subtype=0,$search='',$rubbish=0){
		$conn=' where 1';
		$where[]=$this->_table;
		$where[]=$rubbish;
		$conn.=' and rubbish=%d';
		if($uid){
			$where[]=$uid;
			$conn.=' and uid=%d';
		}
		if($bid){
			$where[]=$bid;
			$conn.=' and bid=%d';
		}
		if($type){
			$where[]=$type;
			$conn.=' and type=%d';
		}
		if($subtype){
			$where[]=$subtype;
			$conn.=' and subtype=%d';
		}
		if($search){
			$where[]='%'.addcslashes($search, '%_').'%';
			
			$conn.=" and subject like %s";
		}
		return DB::result_first('select count(*) from %t '.$conn,$where);
	}
	public function fetch_all_by_uid_bid($uid=0,$bid=0,$start=0,$perpage=0,$type=0,$subtype=0,$order=0,$search='',$rubbish=0){
		$conn=' where 1';
		$where[]=$this->_table;
		$where[]=$rubbish;
		$conn.=' and rubbish=%d';
		if($uid){
			$where[]=$uid;
			$conn.=' and uid=%d';
		}
		if($bid){
			$where[]=$bid;
			$conn.=' and bid=%d';
		}
		if($type){
			$where[]=$type;
			$conn.=' and type=%d';
		}
		if($subtype){
			$where[]=$subtype;
			$conn.=' and subtype=%d';
		}
		if($search){
			$where[]='%'.addcslashes($search, '%_').'%';
			
			$conn.=" and subject like %s";
		}
		if($order){
			if($order=='view'){
				$conn.=' order by '.addslashes($order).' desc';
			}else{
				$conn.=addslashes($order);
			}
		}else{
			$conn.=' order by id desc';
		}
		
		if(isset($start)&&isset($perpage)){
			$where[]=$start;
			$where[]=$perpage;
			$conn.=' limit %d,%d';
		}
		return DB::fetch_all('select * from %t '.$conn,$where);
	}
	public function fetch_all_by_uid_bid_view($uid=0,$bid=0,$start=0,$perpage=0,$rubbish=0){
		$conn=' where 1';
		$where[]=$this->_table;
		$where[]=$rubbish;
		$conn.=' and rubbish=%d';
		if($uid){
			$where[]=$uid;
			$conn.=' and uid=%d';
		}
		if($bid){
			$where[]=$bid;
			$conn.=' and bid=%d';
		}
		$conn.=' order by view desc';
		if(isset($start)&&isset($perpage)){
			$where[]=$start;
			$where[]=$perpage;
			$conn.=' limit %d,%d';
		}
		return DB::fetch_all('select * from %t '.$conn,$where);
	}
	public function update_view_by_gid($gid=0){
		return DB::query('update %t set view=view+1 where id=%d',array($this->_table,$gid));
	}
	public function fetch_thread_all_block($con='',$sc='',$items=0){
		return DB::fetch_all("select * from %t $con $sc limit 0,%d",array($this->_table,$items));
	}
	public function count_by_type(){
		return DB::fetch_all('select type,count(*) num from %t group by type',array($this->_table));
	}
	public function fetch_all_by_recommend($recommend=0,$start=0,$perpage=0){
		return DB::fetch_all('select * from %t where sign=%d and rubbish=0 limit %d,%d',array($this->_table,$recommend,$start,$perpage));
	}
}




?>